package com.xjtu.platform.user.consultor.addconsult;

import com.xjtu.platform.common.CommonService;
import com.xjtu.platform.common.CurrentUser;
import com.xjtu.platform.common.Result;
import com.xjtu.platform.common.TokenUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

import static com.xjtu.platform.common.Result.WARN_CODE_GO;

@RestController
@RequestMapping("/security/addconsult")
public class AddCousultAPI {


    @Resource
    AddConsultService addConsultService;
    @Resource
    CommonService commonService;


    @RequestMapping(value = "/getInfo",method = RequestMethod.POST)
    Result getInfo(@RequestBody AddConsultDto dto, @RequestHeader("Token") String Token){

        CurrentUser currentUser = TokenUtils.getUserInfo(Token,commonService);
        dto.setUser_id(currentUser.getUserId());
        Map<String,Object> page = addConsultService.getInfo(dto);
//        System.out.println(page);
        return Result.success(page);
    }

    @RequestMapping(value = "/addConsult",method = RequestMethod.POST)
    Result addConsult(@RequestBody AdditionDto dto, @RequestHeader("Token") String Token){
        if(addConsultService.addConsult(dto)){return Result.success();}
        return Result.fail(WARN_CODE_GO,"已存在待审核申请");
    }

    @RequestMapping(value = "/checkAdd",method = RequestMethod.POST)
    Result checkAdd(@RequestBody AdditionDto dto, @RequestHeader("Token") String Token){

        int result = addConsultService.checkAdd(dto);
        return Result.success(result);

    }


    @RequestMapping(value = "/getResult",method = RequestMethod.POST)
    Result getResult(@RequestBody AdditionDto dto, @RequestHeader("Token") String Token){

        int ok = addConsultService.getResult(dto);

        if (ok==0){
            return Result.success("申请审核中 ");
        }else if (ok==1){
            return Result.success("审核通过");

        }else if (ok ==2){
            return Result.success("审核未通过");
        }if (ok==500){
            return Result.success("未提交追加咨询申请");
        }
        else {
            return Result.success("未提交追加咨询申请 ");
        }
    }

}
